package com.hackerrank.www.datastructures;

import java.util.*;

/**
 * Created by 27340 on 2017/5/4.
 */
public class DynamicArray {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        String firstLine = scan.nextLine();
        String[] params = firstLine.split(" ");
        //seqNum is the N
        int seqNum = Integer.parseInt(params[0]);
        HashMap<Integer,ArrayList> map = new HashMap<Integer, ArrayList>();
        for(int index=0;index<seqNum;index++){

            map.put(index,new ArrayList());

        }
        int queries = Integer.parseInt(params[1]);
        int lastAns = 0;
        Queue<String> queue = new ArrayDeque<String>();
        for(int index=0;index<queries;index++){
            String query = scan.nextLine();
            String[] queryElems = query.split(" ");
            int queryType = Integer.parseInt(queryElems[0]);
            int x = Integer.parseInt(queryElems[1]);
            int y = Integer.parseInt(queryElems[2]);
            if(queryType==1){
                System.out.println("x is "+ x +" lastAns is "+lastAns+" seqNum is "+
                        seqNum+"( x^lastAns)%seqNum: " + (x^lastAns)%seqNum + " add elem " +y);
                map.get((x^lastAns)%seqNum).add(y);
            }else{
//                   queue.add(query);
                System.out.println("x is " + x +" last is " + lastAns + "n is " + seqNum +"c is " + lastAns +" y is " + y );
                lastAns = (x^lastAns)%seqNum;
                ArrayList list = map.get(lastAns);
                System.out.println(lastAns = (Integer) list.get(y%list.size()));
            }
        }
//        while (!queue.isEmpty()){
//            String query = queue.poll();
//            System.out.println("query is " + query);
//            String[] queryElems = query.split(" ");
//            int x = Integer.parseInt(queryElems[1]);
//            int y = Integer.parseInt(queryElems[2]);
//            lastAns = (x^lastAns)%seqNum;
//            System.out.println("lastAns is " + lastAns);
//            ArrayList list = map.get(lastAns);
//            System.out.println("y is " + y );
//            System.out.println("list.size() is " + list.size() );
//            System.out.println(list.get(y%list.size()));
//        }
    }

}
